/**
 * Created by Administrator on 2016/7/6.
 */
var user_token =  sessionStorage.user_token;
$(document).ready(function(){
    var height = $(window).height();
    $(".button").css("top",height-130);
});

//请求通知列表
$(document).ready(function(){
    var u_id = sessionStorage.u_id;
    //强制ajax同步
    $.ajaxSettings.async=false;
    $.post(commonval+"/user_notice",{
        u_id:u_id,
        user_token:user_token,
        device:"wap",
    },function(data){
        if(data.status==1){
            console.log(data);
            $("#informList").css("display","block");
            var consultList = new Vue({
                el: '#informList',
                data: {
                    items: data.data
                }
            })
        }else{
            $("header p:last-child").css("display","none");
            $(".noInform").css("display","block");
        }
    })
});

//删除逻辑
$(document).ready(function(){
    var num = 0
    $("header p:last-child").click(function(e){
        num++;
        if(num%2 == 1){
            $(this).text("取消编辑");
            $("#informList section img:nth-last-child(4)").css("display","inherit");
            $("#informList section p").addClass("short");
            $(".button").css("display","block");
            $("#informList section").unbind("click");
        }else if(num%2 == 0){
            $(this).text("编辑");
            $("#informList section img:nth-last-child(4)").css("display","none");
            $("#informList section p").removeClass("short");
            $(".button").css("display","none");
            $("#informList section").click(function(){
                var order_num = $(this).children(".order_num").text();
                var check_type = $(this).children(".check_type").text();
                var updateID =$(this).children(".id").text();
                //强制ajax同步
                $.ajaxSettings.async=false;
                $.post(commonval+"/set_notice",{
                    notice_id:updateID,
                    user_token:user_token,
                    device:"wap",
                },function(data){
                    console.log(data);
                })
                if(order_num ==''){
                    location.href="doctorJoin.html";
                }else{
                    location.href="order.html?order_num="+order_num;
                    sessionStorage.check_type =check_type;
                }
            })
        }
        e.stopPropagation();
    })
    $(".button button").click(function(){
        var notice_ids =$("#informList section img.count").parent("section").children(".id").eq(0).text();;
        var item = $("#informList section img.count").parent("section").children(".id");
        if(item.length>0){
            for (var i =1;i<item.length;i++){
                var item1 = $("#informList section img.count").parent("section").children(".id").eq(i).text();
                notice_ids = notice_ids+","+item1;
            }
        }
        var updateID =$(this).children(".id").text();
        //强制ajax同步
        $.ajaxSettings.async=false;
        $.post(commonval+"/deleteNotice",{
            notice_ids:notice_ids,
            user_token:user_token,
            device:"wap",
        },function(data){
            location.href="inform.html";
        })
    })
});

//通知选中逻辑
$(document).ready(function(){
    $("#informList section img:nth-last-child(4)").click(function(e){
        $(this).toggleClass("count");
        if($(this).hasClass("count")){
            $(this).attr("src","../images/chooseAlready.png");
        }else{
            $(this).attr("src","../images/choose.png");
        }
        e.stopPropagation();
    })
});

//通知列表跳转逻辑
$(document).ready(function(){
    $("#informList section").click(function(){
        var order_num = $(this).children(".order_num").text();
        var check_type = $(this).children(".check_type").text();
        var updateID =$(this).children(".id").text();
        //强制ajax同步
        $.ajaxSettings.async=false;
        $.post(commonval+"/set_notice",{
            notice_id:updateID,
            user_token:user_token,
            device:"wap",
        },function(data){
           console.log(data);
        })
        if(order_num ==''){
            location.href="doctorJoin.html";
        }else{
            location.href="order.html?order_num="+order_num;
            sessionStorage.check_type =check_type;
        }
    })
});